package com.java2007.dao.impl;


import com.java2007.dao.AdminDao;
import com.java2007.pojo.Admin;
import com.java2007.util.JdbcUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * 用户持久实现层
 */
public class AdminDaoImpl implements AdminDao {
    /**
     * 通过用户名查询用户
     * @param adminName
     * @return
     */
    @Override
    public Admin selectByUserName(String adminName) throws SQLException {
        QueryRunner qr=new QueryRunner(JdbcUtil.getDataSource());
        String sql="SELECT admin_id adminId,username username,`password` password,admin_status adminStatus,role role from t_admin where username=?";
        return qr.query(sql,new BeanHandler<>(Admin.class),adminName);
    }
}
